﻿@{
    ViewBag.Title = "查看任务日志";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript"> 
        $(function () {
            $.post('/SysMenu/GetDBListInnerJob', function (result) {
                for (var i = 0; i < result.length; i++) {
                    $("#sel_DBName").append("<option value='" + result[i].DBName + "'>" + result[i].DisplayName + "</option>");
                }
            }); 
        });

        function reload() {
            InitList();
        }

        function btnSearch_Click() {
            $("#msg").html("");
            thisPageNum = 1;
            InitList();
        }
        function InitList(postUrl) {
            var dbName = $("#sel_DBName").val(); 
            var postData = { taskName: $.trim($("#txt_TaskName").val()), taskType: $.trim($("#ddl_TaskType").val()), taskStatus: $.trim($("#ddl_TaskStatus").val()), dbName: dbName };

            $("#DataGrid").dg({
                rows: 15,
                height: 400,
                url: "/JobTask/GetAllTask",
                para: postData,
                idField: "GUID",
                checkbox: false,
                rownumbers: true,
                columns: [
                    { field: 'TaskName', title: '任务名称', width: 20 },
                    { field: 'StepName', title: '任务明细', width: 30 },
                    { field: 'StartTime', title: '开始时间', width: 15, align: 'center' },
                    { field: 'EndTime', title: '结束时间', width: 15, align: 'center' },
                    { field: 'RunDuration', title: '持续时间', width: 8, align: 'center' },
                    { field: 'TaskStatus', title: '执行状态', width: 7, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var img = "";
                            var alt = "";
                            if (value == 0) {
                                img = "stop.jpg";
                                alt = "任务暂停";
                            }
                            else if (value == 1) {
                                img = "start.jpg";
                                alt = "任务启动";
                            }
                            else if (value == 2) {
                                img = "tree_dnd_yes.png";
                                alt = "任务成功";
                            }
                            else if (value == 3) {
                                img = "no.png";
                                alt = "任务失败";
                            }
                            var format = "<img src='/images/" + img + "' alt='" + alt + "' width='15' />";
                            return format;
                        }
                    },
                    { field: 'GUID', title: '查看', width: 5, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            return "<a onclick='ViewInfo(\"" + value + "\",\"\");' class='grid_a'>查看</a>";
                        }
                    }
                ]
            });
        }

        function ViewInfo(id, name) {
            $.post("/JobTask/GetTaskLogItem/?dbName=" + $("#sel_DBName").val() + "&id=" + id, function (res) {
                jv.SetDivJson($("#LogInfoDialog"), 4, res);
                $("#spa_TaskName").html(name);
            });
            $('#LogInfoDialog').show();
            $('#LogInfoDialog').dialog({
                title: '查看日志信息',
                top: 80,
                buttons: [{
                    text: '关闭',
                    handler: function () {
                        $('#LogInfoDialog').dialog('close');
                    }
                }]
            });
        }
          
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                任务执行日志搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                选择实例：
                <select id="sel_DBName">
                <option value="">--请选择--</option>
                </select>
                任务名称：
                <input id="txt_TaskName" type="text" style="width: 150px;" />
                明细类型：
                <select id="ddl_TaskType">
                    <option value="">--请选择--</option>
                    <option value="E">抽取任务</option>
                    <option value="EAN">通知源系统</option>
                    <option value="EP">回调源系统</option>
                    <option value="ECAN">源系统回调通知</option>
                    <option value="ODS">加工可操作数据源</option>
                    <option value="DQ">加工数据质量</option>
                    <option value="DQAN">数据质量通知</option>
                    <option value="T">加工模型</option>
                    <option value="TargetSystem">加工对接系统索引表</option>
                    <option value="L">推送任务</option>
                    <option value="TAN">通知对接系统</option>
                    <option value="LP">回调对接系统</option>
                    <option value="TCAN">对接系统回调通知</option>
                </select>
                明细状态:
                <select id="ddl_TaskStatus">
                    <option value="">--请选择--</option>
                    <option value="0">暂停</option>
                    <option value="2">成功</option>
                    <option value="3">失败</option>
                </select>
                <input id="btnSearch" type="button" class="button" value=" 搜索 " onclick="btnSearch_Click()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="600">
                查看任务执行日志
            </td>
            <td align="right"> 
            </td>
        </tr>
    </table>
    <table id="DataGrid" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
<div id="LogInfoDialog" style="padding: 5px; width: 500px; height: 330px; display: none;
    word-wrap: break-word; word-break: normal; line-height: 20px;">
    <div style="width: 470px; height: 245px; overflow-y: scroll;">
        <b>任务明细：</b><span id="spa_StepName"></span><br />
        <b>开始时间：</b><span id="spa_StartTime"></span><br />
        <b>结束时间：</b><span id="spa_EndTime"></span><br />
        <b>持续时间：</b><span id="spa_RunDuration"></span><br />
        <b>执行时间：</b><span id="spa_BatchTime"></span><br />
        <b>执行结果：</b><span id="spa_Result"></span><br />
        <b>执行状态：</b><span id="spa_TaskStatus"></span><br />
    </div>
</div>
